/*
 * @Date: 2020-08-24 09:14:18
 * @LastEditors: xujianxing
 * @LastEditTime: 2020-08-25 17:53:41
 * @FilePath: \nili\src\main.ts
 */
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {
  LoggerMiddleware,
  LoggerFunc,
} from './common/middleware/Logger.middleware';
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
import { ValidationPipe } from '@nestjs/common'; // 自带验证器给力
import { AuthGuard } from './common/guard/auth.guard';
import { LoggingInterceptor } from './common/interceptor/logging.interceptor';
import { TransformInterceptor } from './common/interceptor/transform.interceptor';
// import { ValidationPipe } from './common/pipe/validation.pipe';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  /** 这些中间件，过滤器，拦截器，参数校验，守卫，都可在 Controller 和 模块依赖注入 和 方法级别使用 */
  /**
   * 应用全局中间件
   */
  app.use(new LoggerMiddleware().use);

  /**
   * 应用全局过滤器
   */
  app.useGlobalFilters(new HttpExceptionFilter());

  /**
   * 引用全局参数校验
   */
  // app.useGlobalPipes(new ValidationPipe());

  /**
   * 应用全局守卫（Guard）
   */
  // app.useGlobalGuards(new AuthGuard());

  /**
   * 应用全局拦截器
   */
  app.useGlobalInterceptors(new TransformInterceptor());

  await app.listen(3621);
}
bootstrap();
